
import os
from datetime import datetime, timedelta, timezone

cameracode_file_29 = "CameraCode_29.txt"
cameracode_file_30 = "CameraCode_30.txt"
cameracode_file_37 = "CameraCode_37.txt"
imgs_file_29 = "imgs_29.txt"
imgs_file_30 = "imgs_30.txt"
imgs_file_37 = "imgs_37.txt"



f1=open(cameracode_file_37, encoding='utf-8')
f2=open(imgs_file_37, encoding='utf-8')

camera_codes = list()
img_codes = list()

while True:
    next_line = f1.readline()
    if next_line:
        next_line = next_line.replace("\n", "")
        next_line_parts = next_line.split(",")
        camera_code = next_line_parts[3]
        camera_codes.append(camera_code)
    else:
        break
f1.close()

while True:
    next_line = f2.readline()
    if next_line:
        next_line = next_line.replace("\n", "")
        img_codes.append(next_line)
    else:
        break
f2.close()

print(f"--------camera_codes:" , camera_codes)
print(f"--------img_codes:" , img_codes)

missing_codes = list()
for item in camera_codes:
    if item not in img_codes:
        missing_codes.append(item)

print(f"--------missing_codes:" , missing_codes)



#
#
# def peel(line_item):
#     line_item = line_item.replace("\n", "")
#     all_parts = str(line_item).split(",")
#     if len(all_parts) > 1:
#         return dict(time = all_parts[0] , code = all_parts[1])
#
#
#
#
# all_line_data = list()
# f4=open('aabbcc.txt', encoding='utf-8')
# #此时只读取了一行
# pre = f4.readline()
# all_line_data.append(peel(pre))
# #利用循环全部读出
# i = 1
# while pre:
#     next_line = f4.readline()
#     all_line_data.append(peel(next_line))
#     pre = next_line
# f4.close()
#
# last_time = None
# for item in all_line_data:
#     item_time = datetime.strptime(item["time"], '%Y-%m-%d %H:%M:%S')
#     if last_time is not None:
#         gap = (item_time - last_time).seconds
#         print(f"-------gap: {gap} , code: {item['code']}")
#     last_time = item_time








#
# all_file_time = []
# def all_file(directory_path):
#     for root, dirs, files in os.walk(directory_path):
#         for file in files:
#             arr = str(file).split(".")
#             # dt = datetime(1970, 1, 1) + timedelta(seconds=int(arr[0]))
#             timestamp = float(f"{int(arr[0])+8 * 3600}.{arr[1]}")
#             all_file_time.append(timestamp)
#
# gaps_in_img = []
# def sort_gap_imgs():
#     all_file_time.sort()
#     last_ts_mills = 0
#     index = 0
#     for ts in all_file_time:
#         tsInMills = round(ts, 3) * 1000
#         if last_ts_mills == 0:
#             last_ts_mills = tsInMills
#         else:
#             gap = tsInMills - last_ts_mills
#             gaps_in_img.append(gap)
#             last_ts_mills = tsInMills
#         index += 1
#         dt = datetime.fromtimestamp(ts, timezone.utc)
#         formatted_date = dt.strftime("%Y-%m-%d %H:%M:%S")
#         print(f"-------formatted_date-----{index}:{formatted_date}")
#     print(f"-------gaps_in_img:{gaps_in_img}")
#
#
# img_gap_diffs = []
# def sort_gap_gaps():
#     # gaps_in_img.sort()
#     last_ts_mills = 0
#     for gap_in_mills in gaps_in_img:
#         if last_ts_mills == 0 :
#             last_ts_mills = gap_in_mills
#         else:
#             gap = gap_in_mills - last_ts_mills
#             img_gap_diffs.append(abs(gap))
#             last_ts_mills = gap_in_mills
#
#     print(f"-------img_gap_diffs:{img_gap_diffs}")
#     print(f"-------max gap:{max(img_gap_diffs)}")
#     print(f"-------img_gap_diffs:{sorted(img_gap_diffs , reverse=True)}")
#
#
#
# all_file("/Users/daxiang/Downloads/20230829")
# sort_gap_imgs()
# sort_gap_gaps()